package com.itheima.controller;

import com.itheima.domain.Result;
import com.itheima.domain.pojo.Dept;
import com.itheima.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/depts")
public class DeptController {
    @Autowired
    private DeptService deptService;
    @RequestMapping
    public Result list(){
        List<Dept> deptList = deptService.selectAll();
        return Result.success(deptList);
    }
    @DeleteMapping
    public Result delete(Integer id){
        deptService.delete(id);
        return Result.success();
    }
    @PostMapping
    public Result save (@RequestBody Dept dept){
        deptService.save(dept);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getInfo (@PathVariable Integer id){
        Dept dept = deptService.getInfo(id);
        return Result.success(dept);
    }
    @PutMapping
    public Result update (@RequestBody Dept dept){
        deptService.update(dept);
        return Result.success();
    }
}
